home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / Source / Main.cp < prev    next >
Encoding:
Text File  |  1998-06-21  |  1.8 KB  |  124 lines  |  [TEXT/CWIE]

  1. #include "EventLoop.h"
  2. #include "Main.h"
  3. #include "InspectorTest.h"
  4. #include "Module.h"
  5. #include "SillyBalls.h"
  6.  
  7. #ifndef __EXCEPTIONS__
  8. #include "Exceptions.h"
  9. #endif
  10. #ifndef __DEBUGGER__
  11. #include "Debugger.h"
  12. #endif
  13.  
  14. #include <exception>
  15.  
  16. void Initialize(void);
  17. void NewBall(void);
  18.  
  19.  
  20. //------------------------------------------------------------------------------
  21.  
  22.     static void unexpected_called()
  23.     {
  24.         DebugStr("\pSomeone called unexpected() - you're hosed.");
  25.     }
  26.  
  27.     static void terminate_called()
  28.     {
  29.         // CodeWarrior's exception code has a habit of calling terminate()
  30.         // if you step over a throw in The Debugger -- we provide an empty 
  31.         // routine here to prevent this from killing the app
  32.     
  33.         DebugStr("\pSomeone called terminate() - you're hosed.");
  34.     }
  35.     
  36.     static void report_exception(const Exception& exc)
  37.     {
  38.         // A real application would report the exception to the user here
  39.         // -- we just log it to the debugger
  40.     
  41.         exc.Log();
  42.         
  43.         Debugger();
  44.     }
  45.  
  46.     static OSStatus run_app(va_list /*arg*/)
  47.     {
  48.         EventLoop* evt_loop = nil;
  49.         
  50.         try
  51.         {
  52.             if (TModule::InitializeModules())
  53.             {
  54.                 Initialize();
  55.                 
  56.             //    InspectorTest();
  57.             
  58.                 EventLoop::Run();
  59.             
  60.                 Finalize();
  61.             }
  62.         }
  63.         catch(...)
  64.         {
  65.             delete evt_loop;
  66.         
  67.             TModule::FinalizeModules();
  68.             
  69.             throw;
  70.         }
  71.  
  72.         delete evt_loop;
  73.  
  74.         TModule::FinalizeModules();
  75.         
  76.         return noErr;
  77.     }
  78.  
  79. /*
  80. class VBase
  81. {
  82. protected:
  83.     fVirtual;
  84. };
  85.  
  86. class A : public virtual VBase
  87. {
  88. public:
  89.     fA;
  90. };
  91.  
  92. class B : public virtual VBase
  93. {
  94. public:
  95.     fB;
  96. };
  97.  
  98. class C : public A, public VBase
  99. {
  100. };
  101.  
  102. static void foobar(void)
  103. {
  104. //    int i = offsetof(C, fVirtual);
  105. }
  106. */
  107.  
  108. int main(void)
  109. {
  110.     set_unexpected(unexpected_called);
  111.     set_terminate(terminate_called);
  112.  
  113.     Exception::SetReportProc(&report_exception);
  114.  
  115.     InitializeDebugger();
  116.  
  117.     Exception::ReportExceptions(run_app);
  118.     
  119.     FinalizeDebugger();
  120.  
  121.     return 0;    
  122. }
  123.  
  124.